package Modelo;

import Controlador.ConnectionDB;
import java.sql.ResultSet;

/**
 * Clase Diseñada para cargar las opciones de determinado SELECT HTML TAG.
 * @author Gitecx
 * @since 1.0
 * @see Visitar http://gitecx.unillanos.edu.co/
 */
public class Selects {
    
     /**
     * @return retorna las opciones para un SELECT HTML TAG que contiene únicamente la lista de plugins que son Analizador o Dual.
     */
    public static String CollectorPlugins() {
        String retorno = "";
        ConnectionDB c = new ConnectionDB();
        if (c.Connect()) {
            try {
                ResultSet result = c.getQuery("select idplugin, name from plugin where type = 'C';");
                while (result.next()) {
                    retorno += "<option value=\""+result.getString(1) +"\">"+result.getString(2) +"</option>\n";
                }
            } catch (Exception e) {
                System.err.println("Error: "+e.getMessage());
                retorno = "";
            }
            finally{
                c.close();
            }
        }
        else{
            retorno = "";
        }
        return retorno;
    }
    
    /**
     * @return retorna las opciones para un SELECT HTML TAG que contiene únicamente la lista de plugins que son Analizador o Dual.
     */
    public static String AnalyzerPlugins() {
        String retorno = "<option value=\"D\">Plugin Por Defecto</option>\n";
        ConnectionDB c = new ConnectionDB();
        if (c.Connect()) {
            try {
                ResultSet result = c.getQuery("select idplugin, name from plugin where type <> 'C';");
                while (result.next()) {
                    retorno += "<option value=\""+result.getString(1) +"\">"+result.getString(2) +"</option>\n";
                }
            } catch (Exception e) {
                System.err.println("Error: "+e.getMessage());
                retorno = "";
            }
            finally{
                c.close();
            }
        }
        else{
            retorno = "";
        }
        return retorno;
    }
    /**
     * @return retorna las opciones para un SELECT HTML TAG que contiene la lista completa de plugins.
     */
    public static String FullPlugins(){
        String retorno = "";
        ConnectionDB c = new ConnectionDB();
        if(c.Connect()){
            try {
                ResultSet result = c.getQuery("SELECT idplugin, name from plugin;");
                while(result.next()){
                    retorno += "<option value=\""+result.getString(1) +"\">"+result.getString(2) +"</option>\n";
                }
            } catch (Exception e) {
                System.err.println("Error: "+e.getMessage());
                retorno = "";
            }finally{
                c.close();
            }
        }
        return retorno;
    }
    /**
     * @return retorna las opciones para un SELECT HTML TAG que contiene la lista completa de incidencias.
     */
    public static String FullIncident(){
        String retorno = "";
        ConnectionDB c = new ConnectionDB();
        if(c.Connect()){
            try {
                ResultSet result = c.getQuery("select code, name from incident;");
                while(result.next()){
                    retorno += "<option value=\""+result.getString(1) +"\">"+result.getString(2) +"</option>\n";
                }
            } catch (Exception e) {
                System.err.println("Error: "+e.getMessage());
                retorno = "";
            }finally{
                c.close();
            }
        }
        return retorno;
    }
    
    public static String FullAgent(){
        String retorno = "";
        ConnectionDB c = new ConnectionDB();
        if(c.Connect()){
            try {
                ResultSet result = c.getQuery("select idagent, name from agent;");
                while(result.next()){
                    retorno += "<option value=\""+result.getString(1) +"\">"+result.getString(2) +"</option>\n";
                }
            } catch (Exception e) {
                System.err.println("Error: "+e.getMessage());
                retorno = "";
            }finally{
                c.close();
            }
        }
        return retorno;
    }
    
    public static String FullAction(){
        String retorno = "";
        ConnectionDB c = new ConnectionDB();
        if(c.Connect()){
            try {
                ResultSet result = c.getQuery("select code, name from action;");
                while(result.next()){
                    retorno += "<option value=\""+result.getString(1) +"\">"+result.getString(2) +"</option>\n";
                }
            } catch (Exception e) {
                System.err.println("Error: "+e.getMessage());
                retorno = "";
            }finally{
                c.close();
            }
        }
        return retorno;
    }
    
    public static String FullVulnerability(){
        String retorno = "";
        ConnectionDB c = new ConnectionDB();
        if(c.Connect()){
            try {
                ResultSet result = c.getQuery("select idvulnerability, name from vulnerability;");
                while(result.next()){
                    retorno += "<option value=\""+result.getString(1) +"\">"+result.getString(2) +"</option>\n";
                }
            } catch (Exception e) {
                System.err.println("Error: "+e.getMessage());
                retorno = "";
            }finally{
                c.close();
            }
        }
        return retorno;
    }
}
